#include <iostream>
#include <algorithm>
#include <cstring>
#include <deque>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;

const int N = 1e6 + 10;
int q[N];
LL s[N];
int main()
{
	int n, m;
	cin >> n >> m;
	//处理为前缀和序列
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	LL res = -1e10;
	int hh = 0, tt = 0;
	for (int i = 1; i <= n; i++) {
		if (i - q[hh] > m) hh++;
		res = max(res, s[i] - s[q[hh]]);
		while (hh <= tt && s[q[tt]] >= s[i]) tt--;
		
		q[++tt] = i;
	}
	cout << res << "\n";
	return 0;
}



int main()
{
	int n, m;
	cin >> n >> m;
	//处理前缀和
	vector<LL> s(n + 1);
	s.push_back(0);
	deque<LL> q;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	q.push_back(0);
	LL res = -1e6;
	for (int i = 1; i <= n; i++) {
		if (i - q.front() > m) q.pop_front();
		res = max(res, s[i] - s[q.front()]);
		while (!q.empty() && s[q.back()] >= s[i]) q.pop_back();
		q.push_back(i);
	}
	cout << res << "\n";
	return 0;
}

